package com.dc.project.controller.manage;

import com.dc.project.constant.ControllerConstant;
import com.dc.project.entity.dto.TemplateDetailAttachmentDto;
import com.dc.project.entity.map.TemplateDetailAttachmentMapVo;
import com.dc.project.entity.query.TemplateDetailAttachmentQuery;
import com.dc.project.entity.vo.TemplateDetailAttachmentVo;
import com.dc.project.service.TemplateDetailAttachmentService;
import com.own.aop.operation.LogOperationModuleAop;
import com.own.aop.permission.PermissionModule;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManageTemplateDetailAttachmentController
 *
 * @author chenxueli
 * @date 2025-03-19 13:23:08
 */
@Slf4j
@Tag(name = "模板详情附件" + ConstantBeanSuffix.CONTROLLER)
@RestController
@LogOperationModuleAop("模板详情附件")
@PermissionModule("template-detail-attachment")
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ControllerConstant.PREFIX_MANAGE_API + "template/detail/attachment")
public class ManageTemplateDetailAttachmentController extends BaseController {

    @Resource
    private TemplateDetailAttachmentService templateDetailAttachmentService;

    @Operation(summary = "查询所有信息")
    @PostMapping("/all")
    public ResultModel<List<TemplateDetailAttachmentVo>> all(
            @RequestBody TemplateDetailAttachmentQuery query
    ) {
        var list = templateDetailAttachmentService.all(query);
        return R.success(list);
    }

    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<TemplateDetailAttachmentVo>> page(
            @RequestBody TemplateDetailAttachmentQuery query
    ) {
        var pageModel = templateDetailAttachmentService.page(query);
        return R.success(pageModel);
    }

    @Operation(summary = "map查询信息")
    @PostMapping("/map")
    public ResultModel<List<TemplateDetailAttachmentMapVo>> map(
            @RequestBody TemplateDetailAttachmentQuery query
    ) {
        var list = templateDetailAttachmentService.map(query);
        return R.success(list);
    }

    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<TemplateDetailAttachmentVo> add(
            @Validated @RequestBody TemplateDetailAttachmentDto dto
    ) {
        dto.check();
        var updateModel = templateDetailAttachmentService.add(dto.toBo());
        return R.success(updateModel);
    }

    @Operation(summary = "修改信息")
    @PutMapping("/{templateDetailAttachmentId}")
    public ResultModel<TemplateDetailAttachmentVo> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentId,
            @Validated @RequestBody TemplateDetailAttachmentDto dto
    ) {
        dto.check();
        var updateModel = templateDetailAttachmentService.update(templateDetailAttachmentId, dto.toBo());
        return R.success(updateModel);
    }

    @ConfirmAop(message = "确认删除该项目？（注意：删除之后无法找回数据，且该项目所有资料会被删除）")
    @Operation(summary = "删除信息")
    @DeleteMapping("/{templateDetailAttachmentId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentId
    ) {
        var updateModel = templateDetailAttachmentService.delete(templateDetailAttachmentId);
        return R.success(updateModel);
    }

    @Operation(summary = "根据id获取信息")
    @GetMapping("/{templateDetailAttachmentId}")
    public ResultModel<TemplateDetailAttachmentVo> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentId
    ) {
        var vo = templateDetailAttachmentService.getById(templateDetailAttachmentId);
        return R.success(vo);
    }

}
